const express = require('express')
const app = express();
const path =  require('path')

app.get("/user",(req,res)=>{
    const {
        userId
    } = req.query

    if(userId !== "001"){
        return res.send({
            code: 100001,
            msg: "查询失败",
            data: null
        })
    }

    res.send({
        code: 100000,
        msg: "查询成功",
        data: {
            name: "侯玉乘",
            age: 18,
            sex: "男"
        }
    })
})

app.get("/userInfo/:userId",(req,res)=>{
    const {
        userId
    } = req.params

    if(userId !== "001"){
        return res.send({
            code: 100001,
            msg: "查询失败",
            data: null
        })
    }

    res.send({
        code: 100000,
        msg: "查询成功",
        data: {
            name: "隔壁老王",
            age: 80,
            sex: "男"
        }
    })
})


app.get("/3",(req,res)=>{
    const filePath = path.resolve(__dirname+"/03query传参.html")
    res.sendFile(filePath)
})

app.get("/4",(req,res)=>{
    const filePath = path.resolve(__dirname+"/04path传参.html")
    res.sendFile(filePath)
})

app.listen(4444,()=>{
    console.log("搭建路由成功,点击: http://127.0.0.1:4444");
})